import java.util.ArrayList;
import java.util.List;

public class convert {
    public String convert(String s, int numRows) {
        if(numRows < 2) return s;
        List<StringBuilder> res = new ArrayList<>();
        for (int i = 0; i < numRows; i++) {
            res.add(new StringBuilder());
        }
        int i = 0, flag = -1;
         for (char c : s.toCharArray()) {
            res.get(i).append(c);
            if(i == 0 || i == numRows - 1) flag = -flag;
            i += flag;
        }
         StringBuilder ret = new StringBuilder();
         for (StringBuilder row : res) {
            ret.append(row);
        }
         return ret.toString();
    }
}
